home *** CD-ROM | disk | FTP | other *** search
- Path: news1.h1.usa.pipeline.com!usenet
- From: grantp@usa.pipeline.com(Pete)
- Newsgroups: comp.lang.c++
- Subject: Re: I Need HELP!
- Date: 25 Jan 1996 00:21:21 GMT
- Organization: Kalevi, Inc.
- Message-ID: <4e6ie1$5qi@news1.usa.pipeline.com>
- NNTP-Posting-Host: pipe3.h1.usa.pipeline.com
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete)
- X-Newsreader: Pipeline USA v3.3.0
-
- On Jan 24, 1996 23:08:44 in article <I Need HELP!>,
- 'jeremyx@ix.netcom.com(Jeremy Johnston )' wrote:
-
- >
- >Does anyone know how do get character input use the goto statement?
- >example,I cant get this to work:
- >________________________
- >
- >main()
- >{
- >char ch;
- >getchar();
-
- Well, the compiler's kind of dumb. It doesn't realize that it should
- do what you want, not what you say. My guess is that you would
- prefer that the character read in by getchar() be placed into
- the variable ch, as it would be the only thing that would make
- any sense, given the code you supplied. So, you should write:
-
- ch = getchar();
-
-
- >if (ch==q)
-
- Hmm. what's q? My guess is that you meant the character 'q'
- rather than some undeclared variable named q. So, try putting
- single quotes around the q, then the code might even compile.
-
- >goto b;
- >
- I'm at a loss as to what you intended here. As you may know,
- instructions you give to the computer are executed in sequence,
- left to right, top to bottom, unless you direct otherwise. The goto
- keyword is such a direction. But, let's analyze this. If ch == 'q'
- the computer is directed to jump to the statement labelled b, and
- the computer will print "it worked" on its standard output device,
- the screen in most cases.
-
- But if the user didn't enter a 'q', then the computer will skip
- the goto instruction and drop down to the next one. Lo and
- behold, the next instruction is the one labelled b and, once
- again, you get "it worked". Is that what you intended?
- Probably not.
-
- >b:printf("it worked");
- >}
- >_______________________
- >Why doesn't this work?
-
- Now you know. :-)
- --
- Pete Grant
- Kalevi, Inc.
- Object Oriented Software Development
-